const Router = require("koa-router");

const {
  register,
  login,
  changePassword,
} = require("../controller/user.controller");
const { auth } = require("../middleware/auth.middleware");

const {
  userValidator,
  verifyUser,
  crpytPassword,
  verifyLonin,
} = require("../middleware/user.middleware");

const router = new Router({ prefix: "/users" });

/**
 * @swagger
 * /:
 *   get:
 *     tags:
 *       - user
 *     description: Returns all user
 *     produces:
 *       - application/json
 *     responses:
 *       200:
 *         description: An array of user
 *         schema:
 *           $ref: '#/definitions/user'
 */
router.get("/", (ctx, next) => {
  ctx.body = "hello koa-router";
});

// 注册接口
router.post("/register", userValidator, verifyUser, crpytPassword, register);

// 登录接口
router.post("/login", userValidator, verifyLonin, login);

// 修改密码
router.patch("/", auth, crpytPassword, changePassword);

module.exports = router;
